package com.example.administrator.yanfoxconn.adapter;

import android.annotation.SuppressLint;
import android.os.Build;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.administrator.yanfoxconn.R;
import com.example.administrator.yanfoxconn.activity.KHMainListActivity;
import com.example.administrator.yanfoxconn.activity.KHPeopleListActivity;
import com.example.administrator.yanfoxconn.bean.KHInfo;

import java.util.List;

import androidx.annotation.RequiresApi;

/**
 * @Description
 * @Author song
 * @Date 9/24/21 3:47 PM
 */
public class KHBodyListAdapter extends BaseAdapter {

    private KHPeopleListActivity activity;
    private List<KHInfo> listMessages;
    private String status;


    public KHBodyListAdapter(KHPeopleListActivity activity, List<KHInfo> listMessages){
        this.activity = activity;
        this.listMessages = listMessages;
    }

    @Override
    public int getCount() {
        return listMessages.size();
    }

    @Override
    public Object getItem(int position) {
        return listMessages.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @SuppressLint("ResourceAsColor")
    @RequiresApi(api = Build.VERSION_CODES.M)
    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        final ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            Log.e("===", "ss");
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.adapter_kh_body_item, null);

            holder.tvNum = (TextView) convertView.findViewById(R.id.tv_num);
            holder.tvName = (TextView) convertView.findViewById(R.id.tv_name);
            holder.tvProblem = (TextView) convertView.findViewById(R.id.tv_problem);
            holder.tvStatus = (TextView) convertView.findViewById(R.id.tv_status);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.tvNum.setText((position+1)+"");
        holder.tvName.setText(listMessages.get(position).getI_SNAME());
        holder.tvProblem.setText(listMessages.get(position).getI_PROBLEMTYPE());
        holder.tvStatus.setText(listMessages.get(position).getI_STATUS());

        return convertView;
    }


    private class ViewHolder {
        public TextView  tvNum, tvName, tvProblem,tvStatus;//序號，姓名，問題類型，狀態

    }

}
